import Vue from 'vue'
import router from '../router/index'
import axios from "axios";
import { getToken, getUsername } from "./cookies";
import { messageFun } from "@/utils/element";

export const request = (config) => {
  const instance = axios.create({
    baseURL: "",
    timeout: 1000 * 10,
  })
  // 请求拦截
  instance.interceptors.request.use(config => {
    config.headers['Token'] = "8d0ad0e9e349ec9c796d7759a5abc7b6";  // 携带token
    config.headers['Username'] = "1572283733@qq.com";  // 携带token
    return config;
  }, err => {
    return err;
  })

  // 响应拦截
  instance.interceptors.response.use(res => {
    return res;
    // if (res.data.resCode === 0) {
    //   return res;
    // } else {
    //   messageFun(res.data.message)
    //   setTimeout(() => {
    //     router.push("/")
    //   }, 1500);
    // }
  }, err => {
    return err
  })
  return instance(config)
}